﻿using BPMN.Application.Contracts.DTO.Disposition;
using BPMN.Application.IService.Disposition;
using BPMN.Domain.Entity.Disposition;
using BPMN.Domain.Entity.Material;
using BPMN.Domain.Entity.Unit;
using BPMN.Domain.ProcessModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Net;

namespace BPMN.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DispositionController : ControllerBase
    {
        public DispositionController(IDispositionService dis)
        {
            Dis = dis;
        }

        public IDispositionService Dis { get; }
        /// <summary>
        /// 添加绩效配置
        /// </summary>
        /// <param name="dis"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddDisposition(disposition dis)
        {
            return Ok(Dis.AddDisposition(dis));
        }
        /// <summary>
        /// 根据id获取绩效配置
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult disposition(int id)
        {
            return Ok(Dis.disposition(id));
        }
        /// <summary>
        /// 分页显示联查
        /// </summary>
        /// <param name="name">工序名称</param>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页面大小</param>
        /// <param name="totalCount">总计</param>
        /// <param name="pagerCount">计数</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDispositions(string name, int pageIndex, int pageSize)
        {
            int totalCount;
            int pagerCount;
            var data = Dis.GetDispositions(name,pageIndex,pageSize,out totalCount,out pagerCount);
            return Ok(new { data, totalCount, pagerCount });
           
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="longs"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult plDelte(string ids)
        {
            List<long> longs = ids.Split(',').Select(x => Convert.ToInt64(x)).ToList();
            return Ok(Dis.plDelte(longs));
        }
        /// <summary>
        /// 修改绩效配置
        /// </summary>
        /// <param name="dis"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult updateDisposition(disposition dis)
        {
            return Ok(Dis.updateDisposition(dis));
        }
        /// <summary>
        /// 工序列表显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetProcessShows()
        {
            
            return Ok(Dis.GetProcessShows());
        }
        /// <summary>
        /// 工艺列表显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetProducts()
        {
            return Ok(Dis.GetProducts());
        }
        /// <summary>
        /// 单位列表显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]

        public IActionResult GetUnits()
        {
            return Ok(Dis.GetUnits());
        }
    }
}
